package com.amikomgamedev.panjatpinang.entities;

import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.ui.activity.BaseGameActivity;

import com.amikomgamedev.panjatpinang.Define;
import com.amikomgamedev.panjatpinang.Utils;

import android.content.Context;

public class Entity_BendaJatuh implements Define {
	private int						BendaJatuh_Type	= -1;

	private float					CurX;
	private float					CurY;

	private boolean					onScreen		= false;

	private Sprite					SprEmber;
	private Sprite					SprKerdus;
	private Sprite					SprMagicJar;
	private Sprite					SprPayung;
	private Sprite					SprTas;

	private float					posXLeft		= POS_X_LEFT_BJ;
	private float					posXRigth		= POS_X_RIGHT_BJ;
	private float					posY			= -120;

	private Rectangle				RctEmber;
	private Rectangle				RctKerdus;
	private Rectangle				RctMagicJar;
	private Rectangle				RctPayung;
	private Rectangle				RctTas;

	private Rectangle				RctBJ;
	private static BaseGameActivity	activity;
	private static Context			context;

	public Entity_BendaJatuh(Sprite sprEmber, Sprite sprKerdus,
			Sprite sprMagicJar, Sprite sprPayung, Sprite sprTas, Context con) {
		context = con;
		activity = (BaseGameActivity) con;

		SprEmber = sprEmber;
		SprKerdus = sprKerdus;
		SprMagicJar = sprMagicJar;
		SprPayung = sprPayung;
		SprTas = sprTas;

		RctEmber = new Rectangle(0, sprEmber.getHeight() / 2,
				sprEmber.getWidth(), sprEmber.getHeight() / 3, activity
						.getEngine().getVertexBufferObjectManager());
		RctEmber.setVisible(false);
		// RctEmber.setColor(255, 0, 250);

		RctKerdus = new Rectangle(0, sprKerdus.getHeight() / 2,
				sprKerdus.getWidth() / 2, sprKerdus.getHeight() / 2, activity
						.getEngine().getVertexBufferObjectManager());
		RctKerdus.setVisible(false);
		// RctKerdus.setColor(255, 0, 250);

		RctMagicJar = new Rectangle(0, sprMagicJar.getHeight() / 2,
				sprMagicJar.getWidth(), sprMagicJar.getHeight() / 2, activity
						.getEngine().getVertexBufferObjectManager());
		RctMagicJar.setVisible(false);
		// RctMagicJar.setColor(255, 0, 250);

		RctPayung = new Rectangle(0, sprPayung.getHeight() / 2,
				sprPayung.getWidth(), sprPayung.getHeight() / 2, activity
						.getEngine().getVertexBufferObjectManager());
		RctPayung.setVisible(false);
		// RctPayung.setColor(255, 0, 250);

		RctTas = new Rectangle(0, sprTas.getHeight() / 2, sprTas.getWidth(),
				sprTas.getHeight() / 2, activity.getEngine()
						.getVertexBufferObjectManager());
		RctTas.setVisible(false);
		// RctTas.setColor(255, 0, 250);

		SprEmber.attachChild(RctEmber);
		SprKerdus.attachChild(RctKerdus);
		SprMagicJar.attachChild(RctMagicJar);
		SprPayung.attachChild(RctPayung);
		SprTas.attachChild(RctTas);

		SprEmber.setPosition(0, -100);
		SprKerdus.setPosition(0, -100);
		SprMagicJar.setPosition(0, -100);
		SprPayung.setPosition(0, -100);
		SprTas.setPosition(0, -100);
	}

	public void setBendaJatuh() {
		BendaJatuh_Type = Utils.getRandomValue(0, 4);
		if (Utils.getRandomValue(0, 1) == 1) {
			SprEmber.setPosition(posXLeft, posY);
			SprKerdus.setPosition(posXLeft, posY);
			SprMagicJar.setPosition(posXLeft, posY);
			SprPayung.setFlippedHorizontal(true);
			SprPayung.setPosition(posXLeft, posY);
			SprTas.setFlippedHorizontal(true);
			SprTas.setPosition(posXLeft, posY);
			CurY = posY;
			CurX = posXLeft;
		} else {
			SprEmber.setPosition(posXRigth, posY);
			SprKerdus.setPosition(posXRigth, posY);
			SprMagicJar.setPosition(posXRigth, posY);
			SprPayung.setFlippedHorizontal(false);
			SprPayung.setPosition(posXRigth, posY);
			SprTas.setFlippedHorizontal(false);
			SprTas.setPosition(posXRigth, posY);
			CurY = posY;
			CurX = posXRigth;
		}
		onScreen = true;
		Utils.TRACE("ini bikin objek");
	}

	public void bjUpdate() {
		CurY += 4f;
		switch (BendaJatuh_Type) {
			case BJ_TYPE_EMBER:
				SprEmber.setPosition(CurX, CurY);
				break;
			case BJ_TYPE_KERDUS:
				SprKerdus.setPosition(CurX, CurY);
				break;
			case BJ_TYPE_MAGIC_JAR:
				SprMagicJar.setPosition(CurX, CurY);
				break;
			case BJ_TYPE_PAYUNG:
				SprPayung.setPosition(CurX, CurY);
				break;
			case BJ_TYPE_TAS:
				SprTas.setPosition(CurX, CurY);
				break;
		}
		if (CurY > GAME_SCREEN_HEIGHT) {
			onScreen = false;
		} else {
			onScreen = true;
		}
	}

	public int getBendaJatuh_Type() {
		return BendaJatuh_Type;
	}

	public void setBendaJatuh_Type(int bendaJatuh_Type) {
		BendaJatuh_Type = bendaJatuh_Type;
	}

	public float getCurX() {
		return CurX;
	}

	public void setCurX(float curX) {
		CurX = curX;
	}

	public float getCurY() {
		return CurY;
	}

	public void setCurY(float curY) {
		CurY = curY;
	}

	public Rectangle getRctPayung() {
		return RctPayung;
	}

	public void setRctPayung(Rectangle rctPayung) {
		RctPayung = rctPayung;
	}

	public Sprite getSprEmber() {
		return SprEmber;
	}

	public void setSprEmber(Sprite sprEmber) {
		SprEmber = sprEmber;
	}

	public Sprite getSprKerdus() {
		return SprKerdus;
	}

	public void setSprKerdus(Sprite sprKerdus) {
		SprKerdus = sprKerdus;
	}

	public Sprite getSprMagicJar() {
		return SprMagicJar;
	}

	public void setSprMagicJar(Sprite sprMagicJar) {
		SprMagicJar = sprMagicJar;
	}

	public Sprite getSprPayung() {
		return SprPayung;
	}

	public void setSprPayung(Sprite sprPayung) {
		SprPayung = sprPayung;
	}

	public Sprite getSprTas() {
		return SprTas;
	}

	public void setSprTas(Sprite sprTas) {
		SprTas = sprTas;
	}

	public Rectangle getRctEmber() {
		return RctEmber;
	}

	public void setRctEmber(Rectangle rctEmber) {
		RctEmber = rctEmber;
	}

	public Rectangle getRctKerdus() {
		return RctKerdus;
	}

	public void setRctKerdus(Rectangle rctKerdus) {
		RctKerdus = rctKerdus;
	}

	public Rectangle getRctMagicJar() {
		return RctMagicJar;
	}

	public void setRctMagicJar(Rectangle rctMagicJar) {
		RctMagicJar = rctMagicJar;
	}

	public Rectangle getRctTas() {
		return RctTas;
	}

	public void setRctTas(Rectangle rctTas) {
		RctTas = rctTas;
	}

	public boolean isOnScreen() {
		return onScreen;
	}

	public void setOnScreen(boolean onScreen) {
		this.onScreen = onScreen;
	}

}
